package tum0r.webengine.config

import tum0r.webengine.models.database.DatabaseConnect

/**
 * 说明: 数据库配置
 *
 * 创建者: tum0r
 *
 * 时间: 2021/8/19 16:14
 */
class DatabaseConfig private constructor() {
    /**
     * 数据库配置类伴生对象
     */
    companion object {
        /**
         * 扫描后的数据库表
         */
        var TABLES: ArrayList<Class<*>>? = null

        /**
         * 数据库连接信息
         */
        val DATABASE_CONNECT_INFO = ArrayList<DatabaseConnect>()

        /**
         * 数据库类型转换，以java中的类型作为key，数据库中的类型作为value
         */
        private val TYPE_CONVERT = LinkedHashMap<String, String>()

        /**
         * 获取数据库类型
         *
         * @param[javaType] Java类型
         */
        fun getConvertedType(javaType: String) = TYPE_CONVERT.getOrDefault(javaType, "TEXT")
    }

    init {
        TYPE_CONVERT["boolean"] = "BOOLEAN"
        TYPE_CONVERT["java.lang.Boolean"] = "BOOLEAN"
        TYPE_CONVERT["byte"] = "TINYINT"
        TYPE_CONVERT["java.lang.Byte"] = "TINYINT"
        TYPE_CONVERT["short"] = "SMALLINT"
        TYPE_CONVERT["java.lang.Short"] = "SMALLINT"
        TYPE_CONVERT["int"] = "INT"
        TYPE_CONVERT["java.lang.Integer"] = "INT"
        TYPE_CONVERT["long"] = "BIGINT"
        TYPE_CONVERT["java.lang.Long"] = "BIGINT"
        TYPE_CONVERT["char"] = "VARCHAR(2)"
        TYPE_CONVERT["java.lang.Character"] = "VARCHAR(2)"
        TYPE_CONVERT["float"] = "FLOAT"
        TYPE_CONVERT["java.lang.Float"] = "FLOAT"
        TYPE_CONVERT["double"] = "DOUBLE"
        TYPE_CONVERT["java.lang.Double"] = "DOUBLE"
        TYPE_CONVERT["java.lang.String"] = "MEDIUMTEXT"

        TYPE_CONVERT["char[]"] = "VARCHAR(255)"
        TYPE_CONVERT["java.lang.Character[]"] = "VARCHAR(255)"
        TYPE_CONVERT["byte[]"] = "MEDIUMBLOB"
        TYPE_CONVERT["java.lang.Byte[]"] = "MEDIUMBLOB"

        TYPE_CONVERT["java.util.Date"] = "DATETIME"
        TYPE_CONVERT["java.sql.Date"] = "DATE"
        TYPE_CONVERT["java.sql.Time"] = "TIME"
        TYPE_CONVERT["java.sql.Timestamp"] = "TIMESTAMP"
    }
}